<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    .box {
        width: 100px;
        height: 50px;
        background-color: green;
    }
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
    const oBox = document.querySelector('.box');
    let flag = true; // true 长大， false 缩小
    let min = 100;
    let max = 200;
    let cur = min;
    let change = () => {
        console.log('---------')
        oBox.style.width = cur + 'px';
        if (flag) {
            cur++;
            if (cur >= max) {
                flag = false; 
            }
        } else {
            cur--;
            if (cur <= min) {
                flag = true; 
            }
        }
    // 变量 长大还是缩小？ 
    }
    //setInterval JS里不够准确 用requestAnimationFrame代替
    (function animloop() {
        change();
        requestAnimationFrame(animloop);
    })()
   
    // requestAnimationFrame(loop);
    </script>
</body>
</html>
